package com.sgb.kjwl.viewmodel.self;

import androidx.databinding.ObservableField;

import com.sgb.kjwl.AppConstant;
import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.user.CompanyInfoEntity;
import com.sgb.kjwl.repository.SelfRepertory;
import com.sgb.kjwl.view.ui.activity.self.ApplyCompanyActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.util.MToast;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ApplyCompanyModel extends BaseViewModel {
    public ObservableField<CompanyInfoEntity> companyInfoEntity = new ObservableField<>(new CompanyInfoEntity());
    private ApplyCompanyActivity activity;
    private SelfRepertory repertory;

    public ApplyCompanyModel(ApplyCompanyActivity activity, SelfRepertory repertory) {
        this.activity = activity;
        this.repertory = repertory;
    }

    public void getCompanyDetailModel(String companyNo) {
        APIManager.getInstance().getUserAPI().getCompanyDetailInfo(companyNo)
                .enqueue(new Callback<BaseEntity<CompanyInfoEntity>>() {
                    @Override
                    public void onResponse(Call<BaseEntity<CompanyInfoEntity>> call, Response<BaseEntity<CompanyInfoEntity>> response) {
                        if (response.body() == null || response.body().getState() == null) {
                            return;
                        }
                        if (response.body().getState().equals(AppConstant.REQEUST_SECCUESS)) {
                            companyInfoEntity.set(response.body().getData());
                        } else {
                            assert response.body() != null;
                            MToast.showToast(activity, response.body().getMsg());
                        }
                    }

                    @Override
                    public void onFailure(Call<BaseEntity<CompanyInfoEntity>> call, Throwable t) {

                    }
                });
    }

//    public void applyCompanyModel(String companyNo) {
//            APIManager.getInstance().getUserAPI().applyCompany(companyNo)
//                    .enqueue(new Callback<BaseEntity>() {
//                        @Override
//                        public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
//                            if (response.body() == null || response.body().getState() == null) {
//                                return;
//                            }
//                            if (response.body().getState().equals(AppConstant.REQEUST_SECCUESS)) {
//                                MToast.showToast(activity,"申请成功，请等待管理员审核");
//                            } else {
//                                assert response.body() != null;
//                                MToast.showToast(activity, response.body().getMsg());
//                            }
//                        }
//
//                        @Override
//                        public void onFailure(Call<BaseEntity> call, Throwable t) {
//
//                        }
//                    });
//    }
}
